﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using LL.Data;


namespace LL.Business
{
    public class ServiceBase : IDisposable
    {
        public ServiceBase()
        {
            UseSharedConnection = false;
        }

        IDbSession dbSession = null;
        public IDbSession DbSession
        {
            get
            {
                return dbSession ?? (dbSession = DbSessionFactory.NewSession());
            }
            set
            {
                if (dbSession != null)
                    dbSession.Dispose();
                dbSession = value;
            }
        }

        public bool UseSharedConnection { get; set; }

        public void Dispose()
        {
            if (UseSharedConnection)
                return;
            DbSession.Dispose();
        }

        public void BeginTranscation()
        {
            DbSession.BeginTranscation();
        }

        public void Commit()
        {
            DbSession.Commit();
        }

        public void Rollback()
        {
            DbSession.Rollback();
        }
    }
}
